<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<div class="middle padtop10 myclear">
	<div class="page-content">
		
		<!-- bread crumb -->
		<p id="bread-crumb">
			<a href="<?php echo base_url();?>">
				<?php echo $lang['home'];?>
			</a>
			<a href="<?php echo site_url('monitor/adsOnlineMonitoring');?>">
				<?php echo $lang['online_ads_monitoring'];?>
			</a>
			<?php echo $lang['online_user_budget_expen_monioring'];?>
		</p>
		<!-- end bread crumb -->
		<h3>
			<?php echo $lang['online_user_budget_expen_monioring'];?>
		</h3>
		<br>
		<form name="frmUser" action="<?php echo site_url('monitor/userBudgetExpenMonitoring/');?>" method="get">
			<p class="text-right padtop10">
				User: <input type="text" name="user" size="20" value="<?php echo $user;?>" />
				&nbsp;|&nbsp;
				Nhóm: <select name="typegroup" onchange="document.frmUser.submit();">
					<option value="-1">- Tất cả -</option>
					<option value="1"<?php if($typegroup == 1) echo ' selected="selected"';?>>Nội bộ</option>
					<option value="2"<?php if($typegroup == 2) echo ' selected="selected"';?>>Khách hàng</option>
				</select>
				&nbsp;|&nbsp;
				Ngày: <input type="text" name="date" id="date" size="20" class="input-time" value="<?php echo $date;?>" />
				<input type="submit" value="Search" style="display:none" />
			</p>
			<?php if(count($items) > 0){?>
			<div>
				<table cellpadding="0" cellspacing="0" width="100%" border="1" class="martop10 tbl-list tablesorter">
				<thead>
					<tr>
						<th class="td-label text-center"><strong>STT</strong></th>
						<th class="td-label"><strong>User ID</strong></th>
						<th class="td-label"><strong>User Name</strong></th>
						<th class="td-label"><strong>Nhóm</strong></th>
						<th class="td-label text-right"><strong>Budget</strong></th>
						<th class="td-label text-right"><strong>Expensed</strong></th>
						<th class="td-label text-right"><strong>Tỉ lệ (%)</strong></th>
					</tr>
				</thead>
				<tbody>
					<?php
					$totalBudget = 0;
					$totalExpen = 0;
					$j = 1;
					foreach ($items as $item)
					{
						$totalBudget += $item->budget;
						$totalExpen += $item->expensed;
					?>
					<tr>
						<td class="text-center"><?php echo ($j);?></td>
						<td><?php echo $item->user_id;?></td>
						<td><?php echo $item->username;?></td>
						<td><?php echo ($item->typegroup == 1 ? 'Nội bộ' : 'Khách hàng')?></td>
						<td class="text-right"><?php echo number_format($item->budget);?></td>
						<td class="text-right"><?php echo number_format($item->expensed);?></td>
						<td class="text-right">
							<?php echo number_format($item->expensed/$item->budget*100, 2);?>
						</td>
					</tr>
					<?php $j++;	}	//end for?>
				</tbody>
				<tfoot>
					<tr>
						<td class="td-label text-right" colspan="4">
							<b>Tổng:</b>
						</td>
						<td class="td-label text-right">
							<b><?php echo number_format($totalBudget);?></b>
						</td>
						<td class="td-label text-right">
							<b><?php echo number_format($totalExpen);?></b>
						</td>
						<td class="td-label text-right">
							<b><?php echo number_format($totalExpen/$totalBudget*100, 2);?></b>
						</td>
					</tr>
				</tfoot>
			</table>
			</div>
			<?php } else echo '<br>Not found data';?>
		</div>
	</form>
</div>
<br><br>
<script type="text/javascript">
$('#date').DatePicker({
	format:'Y-m-d',
	date: '<?php echo $date;?>',
	starts: 1,
	onChange: function(formated, dates){
		$('#date').val(formated);
		$('#date').DatePickerHide();
		document.frmUser.submit();
	}
});

$(document).ready(function(){
	$('.tablesorter').tablesorter({textExtraction: function(node){
		var val = node.innerHTML;
		val = val.replace(/,/g, '');
		return val;
	},
		sortList: [[0,0]],
		sortMultiSortKey: 'ctrlKey',
		headers: {
			//1: {sorter: false}
		}
	});
});
</script>